/*
-------------------------------------------------------------
*****************  乐度网店系统(lodoeshop)  *****************

作者：福州市好格网络技术有限公司
网站：http://www.lodoeshop.com
版权：版权属于福州市好格网络技术有限公司，不得拷贝、修改，侵权必究。

*************************************************************
-------------------------------------------------------------
*/
//默认选中商品
var cart_global={
	pro_options:{
		Pro_Count:0,//已选中的商品数量
		Pro_Total:0,//已选中的商品金额
		Pro_Points:0,//已选中的商品总积分
		Pro_item:{}//已选中的商品列表{cartId:购物车ID,price:购买价格,points:所得积分,buysum:购买数量}
	},
	show:function(){
		var Pro_Count=0,Pro_Total=0,Pro_Points=0;
		$.each(this.pro_options.Pro_item,function(key,Pitem){
			Pro_Count++;
			Pro_Total+=(Pitem.price*Pitem.buysum);
			Pro_Points+=(Pitem.points*Pitem.buysum);
		});
		$.extend(this.pro_options,{Pro_Count:Pro_Count,Pro_Total:Pro_Total,Pro_Points:Pro_Points});
		
		
		//$("#cart_goods_sum")
		
	},
	addCart:function(cartid){//将选中的产品加入到已选择列表中
		var cartitem=$("#cart_goods_info>table>tbody>tr.cartgoods[cartid='"+cartid+"']");
		var price=cartitem.attr("price");
		var points=cartitem.attr("points");
		var qn=cartitem.attr("qn");
		var accessoriesno=cartitem.attr("accessoriesno");
		var buysum=cartitem.attr("buysum");
		this.pro_options.Pro_item[cartid]={
			cartId:cartid,
			price:price,
			points:points,
			buysum:buysum
		};
		this.show(cartid);
	},
	removeCart:function(cartid){//在已选择的列表中去掉未选中的产品
		delete this.pro_options.Pro_item[cartid];
		this.show();
	},
	init:function(){
		
	}
};
var cart_totalprice=0;//购物车内已选中金额
var cart_totalpoints=0;//购物车内已选中积分
function isnumber(e){
	if(!isDigit(e.value)){
		alert(lodo_lang_js.cart1.tip_1);
		e.value=1;
		return false;
	}
	if(e.value<=0){
		alert(lodo_lang_js.cart1.tip_2);
		return false;
	}
}

function Goods_cal(cartid,s,lvtype){
	var qs=s;
	if(s<0){s=s*-1;}
	var tempGN=$("#req_good_num"+cartid);
	var lodo_goods_quantity=$("#lodo_goods_quantity_"+cartid+"").val();
	if(lvtype==1){if(qs>0){qs=1;}else{qs=-1;}}
	var buysum=(eval(tempGN.val())+eval(qs));
	if (buysum>0){
		if(buysum>eval(lodo_goods_quantity)&&(lodo_goods_quantity!="-1")){alert(lodo_lang_js.cart1.tip_3.replace("{$1}",lodo_goods_quantity));return;}
		if(lvtype==1&&buysum<eval(s)){alert(lodo_lang_js.cart1.tip_4.replace("{$1}",s));return;}
		upcartgoodslist(cartid,buysum,tempGN);
	}
}


function cart_goods_total(){
	var cart_goods_sum=0;
	var cart_goods_totalprice=0;
	var cart_goods_points=0;
	var cart_goods_totalpoints=0;
	var cart_goods_accessories_sum=0;
	var cart_goods_accessories_totalprice=0;
	var cart_goods_accessories_totalpoints=0;
	var cart_accessories_no=false;
	var cart_goods_price=0;
	$("#cart_goods_info>table>tbody>tr.cartgoods.buy-selected").each(function(){
		var tmp_buysum=$(this).attr("buysum")*1;
		var tmp_price=$(this).attr("price");
		var tmp_points=$(this).attr("points");
		var tmp_cartid=$(this).attr("cartid");
		var tmp_accessoriesno=$(this).attr("accessoriesno");
		 cart_goods_sum+=tmp_buysum;
		 cart_goods_price+=(tmp_buysum*tmp_price);
		 cart_goods_points+=(tmp_buysum*tmp_points);
		 
		 if(tmp_accessoriesno=="true"){
			 cart_accessories_no=true;
			 var cart_accessories_totalprice=0;
			 var cart_accessories_sum=0;
			 var cart_accessories_totalpoints=0;
			 $("#cart_goods_info>table>tbody>tr.cartgoodsaccessories[pcartid='"+tmp_cartid+"']>td>table>tbody>tr.cart_goods_accessories_tr").each(function(){
				var tmp_accessories_buysum=$(this).attr("buysum")*1;
				var tmp_accessories_price=$(this).attr("price");
				var tmp_accessories_points=$(this).attr("points");
				cart_accessories_totalprice+=(tmp_accessories_buysum*tmp_accessories_price);
				cart_accessories_totalpoints+=(tmp_accessories_buysum*tmp_accessories_points);
				cart_accessories_sum+=tmp_accessories_buysum
			});
			$("#cart_goods_"+tmp_cartid+"_accessories_totalprice").html(FormatNumber(cart_accessories_totalprice,2));
			$("#cart_goods_"+tmp_cartid+"_accessories_sum").html(cart_accessories_sum);
			$("#cart_goods_"+tmp_cartid+"_accessories_totalpoints").html(cart_accessories_totalpoints);
			cart_goods_accessories_sum+=cart_accessories_sum;
			cart_goods_accessories_totalprice+=cart_accessories_totalprice;
			cart_goods_accessories_totalpoints+=cart_accessories_totalpoints;
		}
	});
	cart_goods_totalprice+=cart_goods_price;
	cart_goods_totalprice+=cart_goods_accessories_totalprice;
	cart_goods_totalpoints=cart_goods_points+cart_goods_accessories_totalpoints;
	if(cart_accessories_no){
		$("#cart_goods_accessories_sum_info,#cart_goods_accessories_totalprice_info,#cart_goods_accessories_totalpoints_info").show();
	}else{
		$("#cart_goods_accessories_sum_info,#cart_goods_accessories_totalprice_info,#cart_goods_accessories_totalpoints_info").hide();	
	}

	$("#cart_goods_accessories_sum").html(cart_goods_accessories_sum);
	$("#cart_goods_accessories_totalprice").html(FormatNumber(cart_goods_accessories_totalprice,2));
	$("#cart_goods_accessories_totalpoints").html(cart_goods_accessories_totalpoints);
	$("#cart_goods_sum").html(cart_goods_sum);
	$("#cart_goods_price").html(FormatNumber(cart_goods_price,2));
	$("#cart_goods_totalprice").html(FormatNumber(cart_goods_totalprice,2));
	$("#cart_goods_points").html(cart_goods_points);
	$("#cart_goods_totalpoints").html(cart_goods_totalpoints);
	
	cart_totalprice=cart_goods_totalprice;
	cart_totalpoints=cart_goods_totalpoints;
	
	//优惠套餐
	var cart_bindgoods_sum=0;
	var cart_bindgoods_price=0;
	var cart_bindgoods_points=0;
	//var cart_bindgoods_list=$("#cart_bindgoods_list>table>tbody>tr.cartbindgoods.buy-selected");
	if($("#cart_bindgoods_list>table>tbody>tr.cartbindgoods").size()>0){
		$("#cart_bindgoods_list>table>tbody>tr.cartbindgoods.buy-selected").each(function(){
			var bindgoods_price=$(this).attr("price")*1;
			var bindgoods_buysum=$(this).attr("buysum")*1;
			var bindgoods_points=$(this).attr("points")*1;
			cart_bindgoods_sum+=bindgoods_buysum;
			cart_bindgoods_price+=(bindgoods_price*bindgoods_buysum);
			cart_bindgoods_points+=(bindgoods_points*bindgoods_buysum);
		});
		$("#cart_bindgoods_sum").html(cart_bindgoods_sum);
		$("#cart_bindgoods_points").html(cart_bindgoods_points);
		$("#cart_bindgoods_price").html(FormatNumber(cart_bindgoods_price,2));
	}else{
		$("#cart_bindgoods_list").remove();
	}
	cart_totalpoints+=cart_bindgoods_points;
	//自选礼包
	var cart_makegoods_sum=0;
	var cart_makegoods_price=0;
	var cart_makegoods_points=0;
	//var cart_makegoods_list=$("#cart_makegoods_list>table>tbody>tr.cartmakegoods.buy-selected");
	if($("#cart_makegoods_list>table>tbody>tr.cartmakegoods").size()>0){
		$("#cart_makegoods_list>table>tbody>tr.cartmakegoods.buy-selected").each(function(){
			var makegoods_points=$(this).attr("points")*1;
			var makegoods_price=$(this).attr("price")*1;
			var makegoods_buysum=$(this).attr("buysum")*1;
			cart_makegoods_sum+=makegoods_buysum;
			cart_makegoods_price+=(makegoods_price*makegoods_buysum);
			cart_makegoods_points+=(makegoods_points*makegoods_buysum);
		});
		$("#cart_makegoods_sum").html(cart_makegoods_sum);
		$("#cart_makegoods_points").html(cart_makegoods_points);
		$("#cart_makegoods_price").html(FormatNumber(cart_makegoods_price,2));
	}else{
		$("#cart_makegoods_list").remove();
	}
	cart_totalpoints+=cart_makegoods_points;
	
	//优惠打折
	var cart_fcgn_totalprice=0;
	$("#cart_fcgnstr_list table>tbody>tr[cartid]").each(function(){
		cart_fcgn_totalprice+=($(this).attr("specialprice")*1);
	});
	
	
	//优惠方案(礼品方案与购物券方案)
	var cart_activity_totalprice=0;
	var cart_activity_totalpoints=0;
	$("#cart_activity_list table>tbody>tr[cartid]").each(function(){
		cart_activity_totalprice+=($(this).attr("price")*1);
		cart_activity_totalpoints+=($(this).attr("points")*1);
	});

	//订单可选
	var cart_orderchoose_totalprice=0;
	$("#cart_orderchoose_list table>tbody>tr[cartid]").each(function(){
		cart_orderchoose_totalprice+=($(this).attr("price")*1);
	});
	cart_totalprice+=cart_bindgoods_price;
	cart_totalprice+=cart_makegoods_price;
	cart_totalprice-=cart_fcgn_totalprice;
	cart_totalprice+=cart_activity_totalprice;
	cart_totalprice+=cart_orderchoose_totalprice;
	cart_totalpoints-=cart_activity_totalpoints;
	cart_totalprice=FormatNumber(cart_totalprice,2);
	$("#cart_totalprice").html(cart_totalprice);
	$("#cart_totalpoints").html(cart_totalpoints);
	shop_cart_load();
	fix_CartBtn_hide();
	dbook_set();
}

function upcartgoodslist(cartid,buysum,qnobj){
	var aidlist=""
	$("#lodo_specialinformation_list form[aid]").each(function(){
	   if(aidlist!=""){aidlist+=","}
	   aidlist+=$(this).attr("aid");
	});
	fix_CartBtn_show(".cart_btn");
	$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=upcart&cartid="+cartid+"&bsum="+buysum+"&aid="+aidlist+"",function(data){
		if(data.errno){alert(data.msg);return false;}
		if(data.gotono){location.href=data.gotourl};
		if(data.no){
			var tmptr=$("tr[cartid='"+cartid+"']");
			$(qnobj).val(data.buysum);
			tmptr.attr("buysum",data.buysum);
			tmptr.attr({"buysum":data.buysum,"price":data.price,"points":data.points});
			if(data.gtype==1||data.gtype==7||data.gtype==8||data.gtype==9||data.gtype==10){
				//商品
				if(data.gtype==1&&data.wp_itemid!=0&&data.wp_buyqn!=0){
					$("#cart_wholesale_info_"+cartid).html(lodo_lang_js.cart1.tip_5.replace("{$1}",data.wp_buyqn).replace("{$2}",data.wp_discount)).show();
				}else{
					$("#cart_wholesale_info_"+cartid).html("").hide();
				}
				$("#cart_goods_"+cartid+"_price").html(FormatNumber(data.price,2));
				$("#cart_goods_"+cartid+"_points").html(data.buysum*data.points);
				$("#cart_goods_"+cartid+"_totalprice").html(FormatNumber(data.buysum*data.price,2));
			}else{
				//配件
				$("#cart_goods_accessories_"+cartid+"_price").html(FormatNumber(data.buysum*data.price,2));
				$("#cart_goods_accessories_"+cartid+"_points").html(data.buysum*data.points);
			}
			Cart_info_load(data);
		}
	});
}

function Cart_info_load(data){
	//判断是否有优惠打折方案
	if(data.dzno){$("#cart_fcgnstr_list").html(data.dzinfo);}
	//判断原购物车内优惠方案送礼品内是否达到条件．如果未达到就删除掉
	$("#cart_activity_list").html(data.slplist);
	//去掉条件未达到的礼品赠送方案，增加达到条件的礼品赠送方案
	$("#lodo_specialinformation_list").html(data.activity_list);
	//是否使用优惠券
	$("#cart_dbook_list").html(data.dbook_info);
	//优惠券信息
	lodo_dbook_no=data.dbook.no;
	lodo_dbook_type=data.dbook.type;//优惠券类型
	lodo_dbook_price=data.dbook.price;//优惠券值
	lodo_dbook_totalprice=data.dbook.cart_price;//优惠的金额
	cart_goods_total();
	if(typeof load_activity_init=="function"){load_activity_init();}
}

function Cart_ocinfo_load(data){
	var oldocprice=$("#cart_orderchoose_totalprice").html()*1;
	var cartnoocprice=cart_totalprice-oldocprice;
	$("#cart_orderchoose_list").html(data.cart_oclist);
	var ocprice=$("#cart_orderchoose_totalprice").html()*1;
	cart_totalprice=FormatNumber((cartnoocprice+ocprice),2);
	$("#cart_totalprice").html(cart_totalprice);
	$("#lodo_orderchoose_list").html(data.oclist);
	fix_CartBtn_hide();
	if(typeof load_orderchoose_init=="function"){load_orderchoose_init();}
}


function nextcart(){
	Upform.submit();
}


function chGiftnum(obj,aid){
	var tempGiveWay=$("#sendQuantity"+aid).val();
	var tempk=$("form#form"+aid+"' input:checkbox:checked[name='Giftch"+aid+"']").size();
	if(eval(tempGiveWay)==0){
		if(tempk<=0){
			alert(lodo_lang_js.cart1.tip_6);
			return false;
		}
	}else{
		if(eval(tempk)>eval(tempGiveWay)){
			alert(lodo_lang_js.cart1.tip_7.replace("{$1}",tempGiveWay));
			return false;
		}
	}
	if(obj.checked){
		$(obj).parents("li[giftid]").addClass("selected");
	}else{
		$(obj).parents("li[giftid]").removeClass("selected");
	}
	
}

function chkDozen(e,lv,lvtype,cartid,Tabobj){
	if(Tabobj==""||Tabobj==undefined){Tabobj="cart_goods_info"}
	var oldbuysum=$("#"+Tabobj+" table>tbody>tr[cartid='"+cartid+"']").attr("buysum");
	var buysum=e.value;
	if(buysum==oldbuysum){return false;}
	if(!isDigit(buysum)){
		alert(lodo_lang_js.cart1.tip_8);
		e.value=oldbuysum;
		e.focus();
		return false;
	}

//	var lodo_goods_quantity=$("#lodo_goods_quantity_"+cartid+"").val();
//	if(buysum>eval(lodo_goods_quantity)&&(lodo_goods_quantity!="-1")){alert("此商品最多只能购买"+lodo_goods_quantity+"件");e.value=oldbuysum;e.focus();return false;}
	if(lvtype==0){
	if ( (buysum<=0 || (buysum % lv) != 0)){
			alert(lodo_lang_js.cart1.tip_9.replace("{$1}",lv));
			e.value=oldbuysum;
			e.focus();
			return false;
		}
	}else{
		if(buysum<lv){
			alert(lodo_lang_js.cart1.tip_10.replace("{$1}",lv));
			e.value=oldbuysum;
			e.focus();
			return false;
		}
	}
	upcartgoodslist(cartid,buysum,$(e));
}
//跳转到订单信息输入页面
function gotocart2(url){
	//loadding("btn_cart_next",lodo_lang_js.cart1.tip_11,"gotocartload",0);
	var tmp_h=$("input:hidden[name='lodo_goods_qno'][value=1]");
	if(tmp_h.size()>0){
		var tmp_str="";
		tmp_h.each(function(){
			if(tmp_str!=""){tmp_str+=","}
			tmp_str+="["+$(this).attr("gname")+"]"
		});
		alert(lodo_lang_js.cart1.tip_12.replace("{$1}",tmp_str));
		removeloadding("btn_cart_next");
		return;
	}
	
	//判断是否达到最低购买金额
	$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=chmm",function(data){
		if(data.errno){alert(data.msg);return false;}
		if(data.ch){
			location.href=url;
		}else{
			alert(lodo_lang_js.cart1.tip_13.replace("{$1}",data.carsum).replace("{$2}",data.mm));
			removeloadding("btn_cart_next");
			return false;
		}
	});
	return true;
}

var lodo_o_pro_price=0;//购物车内商品金额
var lodo_dbook_no=false;
var lodo_dbook_type=0;//优惠券类型
var lodo_dbook_price=0;//优惠券值
var lodo_dbook_totalprice=0;//优惠的金额

function dbook_set(){
	//var cart_totalprice=$("#cart_totalprice").html()*1;
	//alert("cart_totalprice="+cart_totalprice);
	if(lodo_dbook_no){
		var cart_dbook_price=lodo_dbook_price;
		if(lodo_dbook_type==1){
			var cart_goods_price=0;
			var cart_goods_accessories_totalprice=0;
			var cart_bindgoods_price=0;
			if($("#cart_goods_info")[0]){
				cart_goods_accessories_totalprice=$("#cart_goods_accessories_totalprice").html()*1;
				cart_goods_price=$("#cart_goods_price").html()*1;
			}
			//if($("#cart_fcgnstr_list")[0]){cart_goods_price=$("#cart_fcgnstr_totalprice").html()*1;}
			//if($("#cart_bindgoods_price")[0]){cart_bindgoods_price=$("#cart_bindgoods_price").html()*1;}
			cart_goods_price=cart_goods_price+cart_goods_accessories_totalprice;//+cart_bindgoods_price;
			cart_dbook_price=cart_goods_price-cart_goods_price*(lodo_dbook_price/10);
		}
		cart_dbook_price*=1;
		cart_totalprice-=cart_dbook_price;
		lodo_dbook_totalprice=cart_dbook_price;
	}else{
		cart_totalprice+=lodo_dbook_totalprice;
		lodo_dbook_totalprice=0;
	}
	if(cart_totalprice<0){cart_totalprice=0;}
	cart_totalprice=FormatNumber(cart_totalprice,2);
	$("#cart_totalprice").html(cart_totalprice);
}


function dbook_ok(){
	var DbookNum=$("#cart_dbook_info input#DbookNum").val();
	if(DbookNum==""){alert(lodo_lang_js.cart1.tip_14);return false;}
	loadding("cart_dbook_msginfo",lodo_lang_js.cart1.tip_15);
	$("#cart_dbook_info,#cart_dbook_msginfo").hide();
	$.getJSON(lodo_web_path+"dbook.asp?act=book&dbooknum="+DbookNum+"",function(data){
		if(data.gotono){location.href=data.gotourl;return false;}
		removeloadding("cart_dbook_msginfo");
		$("#cart_dbook_info").show();
		if(data.errno){alert(data.msg);return false;}
		if(data.ch){
			$("#cart_dbook_info").hide();
			$("#cart_dbook_msginfo span.info").html(data.msg);
			$("#cart_dbook_msginfo").show();
			lodo_dbook_no=true;
			lodo_dbook_type=data.type;
			lodo_dbook_price=data.num;
			dbook_set();
		}
	})
}

function dbook_del(){
	$("#cart_dbook_info,#cart_dbook_msginfo").hide();
	loadding("cart_dbook_msginfo",lodo_lang_js.cart1.tip_15);
	$.getJSON(lodo_web_path+"dbook.asp?act=del",function(data){
		if(data.gotono){location.href=data.gotourl;return false;}
		removeloadding("cart_dbook_msginfo");
		if(data.errno){alert(data.msg);return false;}
		if(data.ch){
			$("#cart_dbook_info input#DbookNum").val("");
			$("#cart_dbook_info").show();
			$("#cart_dbook_msginfo span.info").html("");
			lodo_dbook_no=false;
			lodo_dbook_type=0;
			lodo_dbook_price=0;
			dbook_set();
		}
	})
}

function cart_delall(){
	$("#btn_cart_delall").hide();
	loadding("btn_cart_delall",lodo_lang_js.cart1.tip_15);
	$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=dellallcart",function(data){
		$("#btn_cart_delall").show();
		removeloadding("btn_cart_delall");
		if(data.errno){alert(data.msg);return false;}
		if(data.gotono){location.href=data.gotourl;}
	})
}


function cart_selected(){
	var xzNum=0;
	if($("#cart_goods_info input[name='cart-items']").size()>0){
		if($("#cart_goods_info input[name='cart-items']:not(:checked)").size()<=0){
			$("#cart-goods-all").attr("checked",true);
			$("#cart-goods-all").parent().addClass("allbuy-selected");
			xzNum++;
		}else{
			$("#cart-goods-all").attr("checked",false);
			$("#cart-goods-all").parent().removeClass("allbuy-selected");
		}
	}else{
		xzNum++;
	}
	if($("#cart_bindgoods_list input[name='cart-items']").size()){
		if($("#cart_bindgoods_list input[name='cart-items']:not(:checked)").size()<=0){
			$("#cart-bindgoods-all").attr("checked",true);
			$("#cart-bindgoods-all").parent().addClass("allbuy-selected");
			xzNum++;
		}else{
			$("#cart-bindgoods-all").attr("checked",false);
			$("#cart-bindgoods-all").parent().removeClass("allbuy-selected");
		}
	}else{
		xzNum++;
	}
	if($("#cart_makegoods_list input[name='cart-items']").size()>0){
		if($("#cart_makegoods_list input[name='cart-items']:not(:checked)").size()<=0){
			$("#cart-makegoods-all").attr("checked",true);
			$("#cart-makegoods-all").parent().addClass("allbuy-selected");
			xzNum++;
		}else{
			$("#cart-makegoods-all").attr("checked",false);
			$("#cart-makegoods-all").parent().removeClass("allbuy-selected");
		}
	}else{
		xzNum++;
	}
	if(xzNum>=3){
		$("#cart-all-yes").attr("checked",true);
		$("#cart-all-yes").parent().addClass("allbuy-selected");
	}else{
		$("#cart-all-yes").attr("checked",false);
		$("#cart-all-yes").parent().removeClass("allbuy-selected");
	}
}




function $favComm(obj){
    var option = {
        autoShare: true,
        cname: "",
        cidList: "",
        uid: "",
        left: 0,
        top: 0
    };
	$.extend(option,obj);
    window._PP_core_FavComm_data = option;
	$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=favcartselect&cartIdList="+option.cidList+"",function(data){
		if(data.errno){MsgInfoShow(data.msg);}
		if(data.gotono){location.href=data.gotourl;}
		if(data.logno){
			FavCommCallback(lodo_lang_js.functions.tip_8,data.gotourl);
			return false;
		}
		if(data.addfavno){
			//$("#goods_favorites_"+data.gid).html(data.user_favorites_total);
			MsgInfoShow(data.msg);
			shop_collection_load();
			return false;
		}
		return false;
	})
	
    function FavCommCallback(msg,gotourl){
        var option = window._PP_core_FavComm_data;
            $loginFrame({
                type:"func",
                check: false,
				checkReady:false,
                model: false,
				title:msg,
				gotourl:gotourl,
                action:function(){
                    $favComm(option)
                },
                "x": option.left,
                "y": option.top,
				width:650
            });
    }
}


//初始化
$(document).ready(function(){
	//加载选中事件处理
	$("input[name='cart-items']").change(function(){
		var cartid=this.value;
		var xzno=0;//0取消选择,1选择
		var tr=$(this).parents("tr[cartid='"+cartid+"']");
		var cartgoodsaccessories_tr=tr.siblings("tr.cartgoodsaccessories[pcartid='"+cartid+"']");
		if(this.checked){
			tr.addClass("buy-selected");
			cartgoodsaccessories_tr.addClass("buy-selected");
			xzno=1;
			
		}else{
			tr.removeClass("buy-selected");
			cartgoodsaccessories_tr.removeClass("buy-selected");
			xzno=0;
			//cart_global.removeCart(cartid);
		}
		cart_selected();
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=cartchoose&cartid="+cartid+"&xzno="+xzno+"",function(data){
			fix_CartBtn_hide();
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};
			Cart_info_load(data);
		})
	});
	
	//所有商品全选处理
	$("#cart-goods-all").change(function(){
		var carchecked=this.checked;
		var xzno=0;//0取消选择,1选择
		var tr=$("#cart_goods_info table>tbody>tr[cartid]");
		if(carchecked){
			tr.addClass("buy-selected");
			$(this).parent().addClass("allbuy-selected");
			xzno=1;
		}else{
			tr.removeClass("buy-selected");
			$(this).parent().removeClass("allbuy-selected");
			xzno=0;
		}
		$("#cart_goods_info input[name='cart-items']").attr("checked",carchecked);
		cart_selected();
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=cartallyes&xzno="+xzno+"&typ=1",function(data){
			fix_CartBtn_hide();
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};
			Cart_info_load(data);
		})
	})
	//所有套餐全选处理
	$("#cart-bindgoods-all").change(function(){
		var carchecked=this.checked;
		var xzno=0;//0取消选择,1选择
		var tr=$("#cart_bindgoods_list table>tbody>tr[cartid]");
		if(carchecked){
			tr.addClass("buy-selected");
			$(this).parent().addClass("allbuy-selected");
			xzno=1;
		}else{
			tr.removeClass("buy-selected");
			$(this).parent().removeClass("allbuy-selected");
			xzno=0;
		}
		$("#cart_bindgoods_list input[name='cart-items']").attr("checked",carchecked);
		cart_selected();
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=cartallyes&xzno="+xzno+"&typ=2",function(data){
			fix_CartBtn_hide();
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};
			Cart_info_load(data);
		})
	});
	
	//所有礼品全选处理
	$("#cart-makegoods-all").change(function(){
		var carchecked=this.checked;
		var xzno=0;//0取消选择,1选择
		var tr=$("#cart_makegoods_list table>tbody>tr[cartid]");
		if(carchecked){
			tr.addClass("buy-selected");
			$(this).parent().addClass("allbuy-selected");
			xzno=1;
		}else{
			tr.removeClass("buy-selected");
			$(this).parent().removeClass("allbuy-selected");
			xzno=0;
		}
		$("#cart_makegoods_list input[name='cart-items']").attr("checked",carchecked);
		cart_selected();
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=cartallyes&xzno="+xzno+"&typ=3",function(data){
			fix_CartBtn_hide();
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};
			Cart_info_load(data);
		})
	});
	
	
	//全选处理
	$("#cart-all-yes").change(function(){
		var carchecked=this.checked;
		var xzno=0;//0取消选择,1选择
		var tr=$("#cart_goods_info table>tbody>tr[cartid],#cart_bindgoods_list table>tbody>tr[cartid],#cart_makegoods_list table>tbody>tr[cartid],#cart_goods_info table>tbody>tr.cartgoodsaccessories[pcartid]");
		if(carchecked){
			xzno=1;
			tr.addClass("buy-selected");
			$(this).parent().addClass("allbuy-selected");
			$("#cart-goods-all,#cart-bindgoods-all,#cart-makegoods-all").parent().addClass("allbuy-selected");
		}else{
			xzno=0;
			tr.removeClass("buy-selected");
			$(this).parent().removeClass("allbuy-selected");
			$("#cart-goods-all,#cart-bindgoods-all,#cart-makegoods-all").parent().removeClass("allbuy-selected");
		}
		$("input[name='cart-items'],#cart-goods-all,#cart-bindgoods-all,#cart-makegoods-all").attr("checked",carchecked);
		
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=cartallyes&xzno="+xzno+"",function(data){
			fix_CartBtn_hide();
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};
			//if(data.ch){$("input[name='cart-items'],#cart-goods-all,#cart-bindgoods-all,#cart-makegoods-all").attr("checked",carchecked);}
			Cart_info_load(data);
		})
	});
	//删除所选
	$(".cart-selected-del").click(function(){
		var cartitems=$("input[name='cart-items']:checked");
		if(cartitems.size()<=0){
			alert("请选择要删除的商品！");
			return false;
		}
		var cartIdList="";
		cartitems.each(function(){
			if(cartIdList!=""){cartIdList+=",";}
			cartIdList+=this.value;
		})
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=delcartselect&cartIdList="+cartIdList+"",function(data){
			fix_CartBtn_hide();
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};
		})
	})
	//移入收藏夹
	$(".cart-selected-fav").click(function(){
		var cartitems=$("#cart_goods_info input[name='cart-items']:checked");
		if(cartitems.size()<=0){
			alert("请选择要收藏的商品！");
			return false;
		}
		var cartIdList="";
		cartitems.each(function(){
			if(cartIdList!=""){cartIdList+=",";}
			cartIdList+=this.value;
		})
		$favComm({cidList:cartIdList});
	});
	
	//选中处理
	$("#cart_goods_info table>tbody>tr[cartid][xzno='1'],#cart_bindgoods_list table>tbody>tr[cartid][xzno='1'],#cart_makegoods_list table>tbody>tr[cartid][xzno='1']").addClass("buy-selected");
	$("#cart_goods_info table>tbody>tr[cartid][xzno='1']").siblings("tr.cartgoodsaccessories[pcartid]").addClass("buy-selected");
	$("#cart_goods_info table>tbody>tr[cartid][xzno='1'] input[name='cart-items'],#cart_bindgoods_list table>tbody>tr[cartid][xzno='1'] input[name='cart-items'],#cart_makegoods_list table>tbody>tr[cartid][xzno='1'] input[name='cart-items']").attr("checked",true);
	
	cart_selected();
	
	
	//$("#btn_cart_delall").click(cart_delall);
	$("#btn_Dbook_ok").click(dbook_ok);
	$("#btn_dbook_del").click(dbook_del);
	var cart_accessories_no=false;
	//购物车商品购买备注保存事件
	$("#cart_goods_info table>tbody>tr[cartid] .btn_cart_save").live("click",function(){
		var obj=$(this);
		var cartid=obj.attr("cartid");
		var save_upform=$("#gcart_upform_"+cartid);
		var options={
				url:lodo_web_path+"ajax_cart_data.asp?act=savegbuynote&cartid="+cartid+"",
				dataType:"json",
				success:function(data){
					removeloadding(obj);
					fix_CartBtn_hide();
					if(data.errno){alert(data.msg);return false;}
					if(data.gotono){location.href=data.gotourl};
					return false;
				}
			}
		 loadding(obj,"","",0);
		 fix_CartBtn_show(".cart_btn");
		save_upform.ajaxSubmit(options);
	});
	
	//购物车商品与配件删除事件
	$("#cart_goods_info table>tbody>tr[cartid] .btn_cart_del,#cart_bindgoods_list table>tbody>tr[cartid] .btn_cart_del,#cart_makegoods_list table>tbody>tr[cartid] .btn_cart_del").live("click",function(){
		var obj=$(this);
		 var cartid=obj.attr("cartid");
		 loadding(obj,"","",0);
		 fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=delcart&rtyp=cart&cartid="+cartid+"",function(data){
				removeloadding(obj);
				fix_CartBtn_hide();
				if(data.errno){alert(data.msg);return false;}
				if(data.gotono){location.href=data.gotourl};
				if(data.ch){
					switch(data.gtype){
						case 8:
						case 1:{
							$("#cart_goods_info table>tbody>tr.cartgoods[cartid='"+data.cartid+"'],#cart_goods_info table>tbody>tr.cartgoodsaccessories[pcartid='"+data.cartid+"']").remove();
							break;}
						case 6:{
							$("#cart_goods_info table>tbody>tr.cart_goods_accessories_tr[cartid='"+data.cartid+"']").remove();
						if($("#cart_goods_info table>tbody>tr.cartgoodsaccessories[pcartid='"+data.pcartid+"'] table>tbody>tr.cart_goods_accessories_tr[cartid]").size()<=0){$("#cart_goods_info table>tbody>tr.cartgoodsaccessories[pcartid='"+data.pcartid+"']").remove();}
							break;}
						case 7:{
							$("#cart_bindgoods_list table>tbody>tr.cartbindgoods[cartid='"+data.cartid+"']").remove();
							break;}
						case 10:{
								$("#cart_makegoods_list table>tbody>tr.cartmakegoods[cartid='"+data.cartid+"']").remove();
								break;
							}
					}
					$("input:hidden#lodo_goods_qno_"+cartid+",input:hidden#lodo_goods_quantity_"+data.cartid+"").remove();
					Cart_info_load(data);
					}
				return false;
			})
		 return false;
	});
	
	if($("#cart_goods_info table>tbody>tr.cartgoodsaccessories[pcartid!=0]").size()>0){cart_accessories_no=true;}
	if(cart_accessories_no){
		$("#cart_goods_accessories_sum_info,#cart_goods_accessories_totalprice_info,#cart_goods_accessories_totalpoints_info").show();
	}else{
		$("#cart_goods_accessories_sum_info,#cart_goods_accessories_totalprice_info,#cart_goods_accessories_totalpoints_info").hide();	
	}
		   
	//购物车内优惠方案删除事件
	$("#cart_activity_list table>tbody>tr[cartid] .btn_cart_delactivity").live("click",function(){
		var cartid=$(this).attr("cartid");
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=delactivity&cartid="+cartid+"",function(data){
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};																	
			if(data.no){Cart_info_load(data);}
		})
	});
	
	//购物车内订单可选删除事件
	$("#cart_orderchoose_list table>tbody>tr[cartid] .btn_cart_deloc").live("click",function(){
		var cartid=$(this).attr("cartid");
		fix_CartBtn_show(".cart_btn");
		$.getJSON(lodo_web_path+"ajax_cart_data.asp?act=deloc&cartid="+cartid+"",function(data){
			if(data.errno){alert(data.msg);return false;}
			if(data.gotono){location.href=data.gotourl};																	
			if(data.no){Cart_ocinfo_load(data);}												   
		})
	});
	
	
	//优惠方案添加
	$("form input[name='btn_cart_addactivity']").live("click",function(){
		var aid=$(this).attr("aid");
		var aname=$(this).attr("aname");
		var sendQuantity=$("form input:hidden#sendQuantity"+aid+"");
		if(sendQuantity[0]){
			var gwnum=sendQuantity.val()*1;
			var gwsum=$("form#form"+aid+" input:checkbox[name='Giftch"+aid+"']:checked").size();
			if(gwsum!=gwnum&&gwnum!=0){
				alert(lodo_lang_js.cart1.tip_16.replace("{$1}",aname).replace("{$2}",gwnum));
				return false;
				}
		}else{
/*			alert("此优惠方案的优惠条件还未达到，无法享受此优惠方案！");
			return false;*/
		}
		fix_CartBtn_show(".cart_btn");
		var btn_cart_addactivity=$(this);
		var options={
				url:lodo_web_path+"ajax_cart_data.asp?act=addactivity&aid="+aid+"",
				dataType:"json",
				success:function(data){
					removeloadding(btn_cart_addactivity);
					if(data.errno){alert(data.msg);return false;}
					if(data.gotono){location.href=data.gotourl};
					if(data.no){
						Cart_info_load(data);
					}
					return false;
				}
			}
		loadding(btn_cart_addactivity,"","",0);
		$("form#form"+aid+"").ajaxSubmit(options);
		return false;
	});
	
	$("#activity_list>div[typ='gift'] input:checkbox:checked").parents("li[giftid]").addClass("selected");
	if(typeof load_activity_init=="function"){load_activity_init();}
	//订单可选添加
	$("form input[name='btn_cart_orderchoose_add']").live("click",function(){
		var ocid=$(this).attr("ocid");		   
		var ocname=$(this).attr("ocname");
		var upform=$("form#ocupform_"+ocid+"");
		var octype=upform.attr("octype");
		var ofch=$("form#ocupform_"+ocid+" input[name='OFch"+ocid+"']:checked");
		if(ofch.size()<=0){
			alert(lodo_lang_js.cart1.tip_17);
			return false;
		}
		var errno=false;
		var ocitemidlist="";
		ofch.each(function(){
			var ocitemid=this.value;
			var tr=$("form#ocupform_"+ocid+" .ocitem[ocitemid="+ocitemid+"]");
			var ocitemname=tr.attr("ocitemname");
			var OcQuantity=$("input#OcQuantity"+ocitemid+"").val();
			if(!isDigit(OcQuantity)){
				alert(lodo_lang_js.cart1.tip_18.replace("{$1}",ocitemname));
				errno=true;
				return false;
			}
			if(OcQuantity<1){
				alert(lodo_lang_js.cart1.tip_19.replace("{$1}",ocitemname));
				errno=true;
				return false;
			}
			var slno=tr.attr("slno");
			var wkno=tr.attr("wkno");
			if(slno==1&&wkno==1){
				var inputOF=$("input#inputOF_"+ocitemid+"").val();
				if(inputOF==""){alert(lodo_lang_js.cart1.tip_20.replace("{$1}",ocitemname));errno=true;return false;}
			}
			if(ocitemidlist!=""){ocitemidlist+=","}
			ocitemidlist+=ocitemid;
		});
		if(errno){return false;}
		var btn_cart_orderchoose_add=$(this);

		var options={
				url:lodo_web_path+"ajax_cart_data.asp?act=addocitem&ocid="+ocid+"&ocitem="+ocitemidlist+"",
				dataType:"json",
				success:function(data){
					removeloadding(btn_cart_orderchoose_add);
					if(data.errno){alert(data.msg);return false;}
					if(data.gotono){location.href=data.gotourl};
					if(data.no){
						Cart_ocinfo_load(data);
						alert(lodo_lang_js.cart1.tip_21);
					}
					return false;
				}
			}
		fix_CartBtn_show(".cart_btn");
		loadding(btn_cart_orderchoose_add,"","",0);
		upform.ajaxSubmit(options);
		return false;
	});
	if(typeof load_orderchoose_init=="function"){load_orderchoose_init();}
})